#ifndef _CONDITIONVARIABLE_H
#define _CONDITIONVARIABLE_H

#include "10_Mutex.hpp"
#include <pthread.h>

// class Mutex; // 需要函数

class ConditionVariable
{
private:
    pthread_cond_t cond;

public:
    ConditionVariable()
    {
        pthread_cond_init(&cond, nullptr);
    }

    ~ConditionVariable()
    {
        pthread_cond_destroy(&cond);
    }

    ConditionVariable(const ConditionVariable&) = delete;
    ConditionVariable& operator=(const ConditionVariable&) = delete;

    void wait(Mutex& mutex)
    {
        pthread_cond_wait(&cond, mutex.native_handle());
    }

    void notify_one()
    {
        pthread_cond_signal(&cond);
    }

    void notify_all()
    {
        pthread_cond_broadcast(&cond);
    }

};

#endif

